package cn.itcast.bos.mq;


import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Service;

@Service("smsConsumer")
public class SmsConsumer implements MessageListener {

	public void onMessage(Message message) {
		
		MapMessage mapMessage =(MapMessage) message;
		
		try {
			String randomCode = RandomStringUtils.randomNumeric(4);
			/*
			String result = SmsUtils.sendSmsByHTTP(mapMessage.getString("telephone")
					,mapMessage.getString("msg")); */
			String result = "000/xxxx";
			if (result.startsWith("000")) {
			
				System.out.println("发送短信成功,手机号："
						+ mapMessage.getString("telephone") 
						+ mapMessage.getString("msg"));
			
			} else {
				throw new RuntimeException("短信发送失败, 信息码："+result);
			}
		} catch (Exception e) {		
			e.printStackTrace();
		}
		
		 
	
	}
	
}
